<template>
    <el-card shadow="never" :body-style="{ padding: '0px' }">
        <div slot="header">编辑用户
            <el-button type="info" icon="el-icon-back" size="mini" plain @click="$router.push({name:'users'})">返回</el-button>
        </div>
     <el-form :model="form" ref="form" label-width="80px">
         <el-form-item label="用户名">
             <el-input v-model="form.username"></el-input>
         </el-form-item>
           <el-form-item label="手机">
             <el-input v-model="form.phone"></el-input>
         </el-form-item>
           <el-form-item label="邮箱">
             <el-input v-model="form.email"></el-input>
         </el-form-item>
           <el-form-item label="性别">
             <el-select v-model="form.gender" placeholder="">
                 <el-option label="男" value="m"> </el-option>
                 <el-option label="女" value="f"> </el-option>
               
             </el-select>
             
         </el-form-item>
         <el-form-item>
             <el-button type="primary" @click="edit()">确定</el-button>
             <el-button>取消</el-button>
         </el-form-item>
     </el-form>
     
    </el-card>
</template>

<script>
    export default {
        props:['id'],
        data(){
            return {
                form:{
                    username:'',
                    phone:'',
                    email:'',
                    gender:'m',
                    id:'',
                }
            }
        },
        created(){
            this.getUser();
        },
        methods:{
            getUser(){
                 this.axios.get(`/users/${this.id}`).then((ret)=>{
                    const {data} =ret.data;
                    this.form.username = data.username;
                    this.form.phone = data.phone;
                    this.form.email = data.email;
                    this.form.gender = data.gender;
                    this.form.id = data.id;
                }).catch(()=>{

                })
            },
            edit(){
               this.axios.put(`/users/edit/${this.id}`,this.form).then(()=>{
                   this.$router.push({
                       name:'users'
                   })
               })
            }
        }
    }
</script>

<style>

</style>
